/**
 * 
 */
package de.cbf.cam.dsa.battle.ui.windows.attackWindow;

import java.awt.event.ActionEvent;

import org.eclipse.swt.widgets.Composite;

import de.cbf.cam.dsa.battle.ui.composites.CompositeDiceCheck;
import de.cbf.cam.dsa.battle.ui.composites.CompositeXDiceOpen;
import de.cbf.cam.dsa.model.interfaces.DiceCompositeActionListener;

class TestListener implements DiceCompositeActionListener{
	CompositeXDiceOpen ownComposite;
	@Override
	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
		if (source instanceof CompositeDiceCheck) {
			CompositeDiceCheck compositeTarget = (CompositeDiceCheck) source;
			boolean sucessfullAttack = compositeTarget.getSuccess();
			if(sucessfullAttack){
				ownComposite.enable();
				ownComposite.rollDice();
			}else{
				ownComposite.disable();
			}
		}					
	}				
	@Override
	public void setDiceComposite(Composite composite) {
		if (composite instanceof CompositeXDiceOpen) {
			CompositeXDiceOpen newComposite = (CompositeXDiceOpen) composite;
			ownComposite = newComposite;
		}					
	}				
	@Override
	public void initFromComposite(Composite composite) {
		if (composite instanceof CompositeDiceCheck) {
			CompositeDiceCheck compositeTarget = (CompositeDiceCheck) composite;
			boolean sucessfullAttack = compositeTarget.getSuccess();
			if(sucessfullAttack){
				ownComposite.enable();
			}else{
				ownComposite.disable();
			}						
		}			
	}
}